// pages/work/index.js

var api = require('../../utils/api.js');
var app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        see:0,
        avatar:'',
        imagea:'',
        imageb:'',
        cimage:'',
        dimage:'',
        eimage:'',
        sex:'女',
        info:{}
    },

    setsex(){
        var sex=this.data.sex;
        console.log(sex);

        sex=sex=='男'?'女':'男';
        
        console.log(sex);

        this.setData({
            sex:sex
        })

    },

    onLoad(){
        wx.showModal({
          title: '温馨提示',
          content: '携号转网的手机号码不能及时接收提醒短信！',
          complete: (res) => {
           
          }
        })
    },

    setsee(ret){
        var see=this.data.see;

        this.setData({
            see:!see
        })
    },

    getvalue(ret){
        console.log(ret);
        var key=ret.currentTarget.dataset.key;
        var value=ret.detail.value;

        var info=this.data.info;

        info[key]=value;

        this.setData({
            info:info
        })


    },
    chooseImage(ret){

        let that = this;
        var usrl=api.HOST;
        console.log(ret);
        var key=ret.currentTarget.dataset.key;

        wx.chooseMedia({
          count: 1,
          mediaType:['image'],
          success: function (res) {
            
 
            let tempFilePaths = res.tempFiles;
       
         
            wx.uploadFile({
              filePath: tempFilePaths[0].tempFilePath,
              name: 'file',
              url: usrl+'common/upload',
              formData:{},
              success:function(res){
                var data= JSON.parse(res.data);

                console.log(key)
                if (key=='avatar'){
                    that.setData({
                        avatar:data.data.fullurl
                    });
                }

                if (key=='imagea'){
                    that.setData({
                        imagea:data.data.fullurl
                    });
                }
                if (key=='imageb'){
                    that.setData({
                        imageb:data.data.fullurl
                    });
                }
                if (key=='cimage'){
                    that.setData({
                        cimage:data.data.fullurl
                    });
                }
                if (key=='dimage'){
                    that.setData({
                        dimage:data.data.fullurl
                    });
                }
                if (key=='eimage'){
                    that.setData({
                        eimage:data.data.fullurl
                    });
                }
              },
              fail: function (res) {
                console.log('上传失败');
                }
            })
          }
        })
    },
    seexieyi3(){
        wx.navigateTo({
          url: '/pages/xieyi/index?id=3',
        })
    },
    seexieyi4(){
        wx.navigateTo({
          url: '/pages/xieyi/index?id=4',
        })
    }, seexieyi5(){
        wx.navigateTo({
          url: '/pages/xieyi/index?id=5',
        })
    },
    submits(){
        var see=this.data.see;
        var info=this.data.info;

        info['sex']=this.data.sex;
        info['avatar']=this.data.avatar;
        info['aimage']=this.data.imagea;
        info['bimage']=this.data.imageb;
        info['cimage']=this.data.cimage; 
        info['dimage']=this.data.dimage;
        info['eimage']=this.data.eimage;
        info['citys']=wx.getStorageSync('address');
         
        console.log(info);

        if(see != 1){
            wx.showToast({
                title: '请阅读并同意协议',
                icon:'none'
            })
            return false;
        }

        api.post({
            url: 'worker/submits',
            data: info,
            success: data => {

                wx.showToast({
                  title: data.msg,
                  icon:'none'
                })

                if(data.code==1){
                    wx.showToast({
                      title: '提交成功，请等待审核！',
                      icon:'none'
                    })
                    setTimeout(function(){
                        wx.switchTab({
                        url: '/pages/my/my',
                        })
                    },2000)
                }
            }
        })


    }
})